package com.agritech.machines;

import com.agritech.factory.AgriculturalMachine;
import com.agritech.observer.EnvironmentData;

/**
 * 收割机类
 */
public class Harvester extends AgriculturalMachine {
    private double cuttingHeight;
    private double harvestSpeed;

    @Override
    public void startOperation() {
        System.out.println(getName() + " 开始收割作业");
    }

    @Override
    public void stopOperation() {
        System.out.println(getName() + " 停止收割作业");
    }

    @Override
    public void executeTask(String task) {
        System.out.println(getName() + " 执行任务: " + task);
    }

    @Override
    protected void adjustOperationStrategy(EnvironmentData data) {
        if (data.getWindSpeed() > 30) {
            System.out.println(getName() + " 风速过高，暂停收割作业");
            stopOperation();
        } else {
            System.out.println(getName() + " 环境正常，继续作业");
            this.harvestSpeed = calculateOptimalSpeed(data);
        }
    }

    private double calculateOptimalSpeed(EnvironmentData data) {
        // 根据环境数据计算最优收割速度
        return 5.0; // 示例固定值
    }
}